<?php

// TITLE: donor
// FILE: donor.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:53:06 PM
?>

		public function createDonor($donationId, $contactId) {
			global $con;
			$sql = 'INSERT INTO donor (donation_id, contact_id) VALUES (' . $donationId . ', ' . $contactId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDonor($id) {
			global $con;
			$sql = 'SELECT * FROM donor WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$donor = new Donor();
				$donor->setDonationId($this->readDonation($result[0]));
				$donor->setContactId($this->readContact($result[1]));
			} else {
				$donor = false;
			}
			return $donor;
		}// end function

		public function updateDonor($donationId, $contactId) {
			global $con;
			$sql = 'UPDATE donor SET donation_id = ' . $donation_id . ', contact_id = ' . $contactId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDonor($id) {
			global $con;
			$sql = 'DELETE FROM donor WHERE donation_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDonor() {
			global $con;
			$sql = 'SELECT * FROM donor';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$donors = array();
				while ($result = mysqli_fetch_array($results)) {
					$donor = new Donor();
					$donor->setDonationId($this->readDonation($result[0]));
					$donor->setContactId($this->readContact($result[1]));
					$donors[] = $donor;
				}// end while
			} else {
				$donors = false;
			}
			return $donors;
		}// end function

